package com.sservice.service.service.impl;

import com.sservice.urp.dao.IPermissionDao;
import com.sservice.urp.entity.Permission;
import com.sservice.urp.vo.PermissionVo;
import com.sservice.service.service.IPermissionService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PermissionServiceImpl implements IPermissionService {

//    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private IPermissionDao userDao;

    @Override
    public List<Permission> queryByPage(PermissionVo user) {
        return null;
    }


    @Override
    public int deleteByPrimaryKey(Integer id) {
        return userDao.deleteByPrimaryKey(id);
    }


    @Override
    public int insertSelective(Permission record) {
        return userDao.insertSelective(record);
    }

    @Override
    public Permission selectByPrimaryKey(Integer id) {
        return userDao.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Permission record) {
        return userDao.updateByPrimaryKeySelective(record);
    }

    @Override
    public List<Permission> getPermissionByUserID(int userid) {
        return userDao.getPermissionByUserID(userid);
    }

    @Override
    public List<Permission> getPermissionByRoleId(int roleId) {
        return userDao.getPermissionByRoleId(roleId);
    }


    @Override
    public int queryCount(PermissionVo user) {
        return 0;
    }
    /**
     * 判断用户是否拥有某项权限
     * @param userId  用户ID
     * @param permissionId  权限ID
     * @param list 权限集合
     * @return
     */
    @Override
    public boolean hasPermission(int userId, int permissionId, List<Permission> list) {
        boolean flag = false;
        for (int i = 0; i < list.size(); i++) {
            Permission p = list.get(i);
            if (p.getId() == 137) {
                flag = true;
            }
        }
        return flag;
    }
}
